
#if 0 // 1启用实示例  0禁用   具体参数配置请到 topic_messenger.h 中修改

#include "topic_messenger.h"

typedef struct
{
    const char *userstr;
    uint32_t id;
} test_user_struct_t;

topic_messenger_handle_t handle = NULL;

void click_theme_cb(void *userdata, size_t len)
{
    // do your thing
    printf("button clicked, userdata is %d\n", *(uint16_t *)userdata);
}

void double_theme_cb(void *userdata, size_t len)
{
    // do your thing
    test_user_struct_t *user = (test_user_struct_t *)userdata;
    printf("button double clicked, user string is %s,user id is %x\n", user->userstr, user->id);
    printf("userdata lenth is %d\n", len);
}

void long_presss_theme_cb(void *userdata, size_t len)
{
    // do your thing
    printf("button long pressed, userdata is %s\n", (const char *)userdata);
}

void get_mutex()
{
    // rtos mutex get
}

void give_mutex()
{
    // rtos mutex give
}

int main()
{

#if 0 // if topic_messenger_support_rtos is on ,if platform is esp, dont need this
    topic_messenger_mutex_cb_t mutex_cb;
    mutex_cb.mutex_get_cb = get_mutex,
    mutex_cb.mutex_give_cb = give_mutex;
    topic_messenger_mutex_register(&mutex_cb);
#endif

    topic_messenger_subscribe(&handle, "button click", click_theme_cb);         // 订阅单击主题事件
    topic_messenger_subscribe(NULL, "button double click", double_theme_cb);    // 使用双击主题事件
    topic_messenger_subscribe(NULL, "button long press", long_presss_theme_cb); // 使用长按主题事件

    topic_messenger_set_priority(NULL, "button click", TOPIC_MESSENGER_PRIORITY_MIDDLE); // 使用主题名更改主题优先级
    topic_messenger_set_priority(handle, NULL, TOPIC_MESSENGER_PRIORITY_HIGH);           // 使用句柄更改主题优先级

    printf("subscribed theme number : %d\n", topic_messenger_subscribe_count()); // 查询已订阅的主题数量

    uint16_t num = 520;
    topic_messenger_msg("button click", &num, sizeof(num)); // 当用户单击按键时  发布主题事件   可携带自定义用户数据

    test_user_struct_t user = {"hello", 0x12345678};
    topic_messenger_msg("button double click", &user, sizeof(user)); // 当用户双击按键时  发布主题事件   可携带自定义用户数据

    char *str = "what a nice day!";
    topic_messenger_msg("button long press", str, strlen(str) + 1); // 当用户长按按键时  发布主题事件   可携带自定义用户数据

    topic_messenger_del(handle);                                                 // 删除单击主题的单个指定订阅
    printf("subscribed theme number : %d\n", topic_messenger_subscribe_count()); // 查询已订阅的主题数量

    topic_messenger_del_by_theme("button double click");                         // 删除双击主题下的所有订阅
    printf("subscribed theme number : %d\n", topic_messenger_subscribe_count()); // 查询已订阅的主题数量

    topic_messenger_del_all();                                                   // 删除所有订阅
    printf("subscribed theme number : %d\n", topic_messenger_subscribe_count()); // 查询已订阅的主题数量

    return 0;
}

#endif